﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Globalization;
using System.Diagnostics;
using System.Collections.Generic;
using VMExplorer.Win32;

namespace VMExplorer.MemoryObjects
{
  /// <summary>
  /// Thread environment blocks
  /// </summary>
  class TEBObject : RemoteMemoryObject<Native.TEB>
  {
    #region Construction

    private TEBObject (SafeProcessHandle hProcess, MemoryAddress baseAddress, int tid)
      : base(hProcess, baseAddress, RegionUsage.Threads) 
    {
			Name = string.Format ("Thread Environment Block ({0:X4})", tid);
    }

		public static IEnumerable<IMemoryObject> Create (SafeProcessHandle hProcess, MemoryAddress baseAddress, int tid)
		{
			List<IMemoryObject> memObjects = new List<IMemoryObject> ();
			if (baseAddress.IsValid)
			{
				#region :: TIB ::

				TEBObject tib = new TEBObject (hProcess, baseAddress, tid);
				memObjects.Add (tib);

				#endregion
				#region :: Heaps ::

        memObjects.Add (new ThreadStackObject (hProcess, tib.Inner.DeallocationStack, string.Format ("Thread stack ({0:X4})", tib.Inner.ThreadID)));

				#endregion
			}
			return memObjects;
    }

    #endregion
  }
}
